jquery adding required to a dropdownbox [SOLVED]

Posted by Crays on Stack Overflow See other posts from Stack Overflow or by Crays
Published on 2013-11-10T12:57:29Z Indexed on 2013/11/10 15:54 UTC
Read the original article Hit count: 153

Filed under:

Hi i would like to know how do i add a required attribute to a dropdownbox? I've search numerous ways but none worked, here's my code

<script>
$(document).ready(function(){
    $('.orderingmenu .burgers').change(function(){
    var selectVal= $(this).val();
    if(selectVal != 'none'){
    $(this).next().attr('required', true);
    }
    });
});
</script>

i am really out of idea on how to do this, i tested the selectors and they're working fine, but it just doesn't seem to add in the required attribute to that select field =/ any help please?

what i have tried is

$(this).next().prop('required', true);
$(this).next().attr('required', 'true');
$(this).next().attr('required', '');
$(this).next().prop('required');

none have worked =/

EDIT the HTML

<div class="orderingmenu" style="margin-bottom: 0.5%;">
        <select name="burgerlist"  class="burgers" style="width: 35%; float: left; font-size: 12px;">
        <option selected="selected" value="none">NONE</option>
        <option value="A">A</option>
        </select>

        <select name="option" id="option" class="setornot" style="width: 30%; font-size: 12px;">
        <option selected="selected" value="none">NONE</option>
        <option value="ALA CARTE">ALA CARTE</option>
        <option value="SET">SET</option>
        </select>

        <input type="text" placeholder="ANY REMARKS?" name="remarks" style="width: 30%; float: right; font-size: 12px;">
        </div>

i had it looped with a php script, but basically what i wanted to do is so that if there is any selection other than 'none', the other selection is required.

EDIT 2

found out the problem was that i had the value for none!

© Stack Overflow or respective owner

Related posts about jQuery